<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.company.DepartmentComInfo" %>
<%@ page import="weaver.hrm.resource.ResourceComInfo" %>
<%@ page import="weaver.meeting.Maint.MeetingRoomReport" %>
<%@ page import="java.util.Calendar" %>
<%
    JSONObject jsonData = new JSONObject();
    RecordSet rs = new RecordSet();
	BaseBean baseBean = new BaseBean();
    String currentdate = Util.null2String(request.getParameter("currentdate"));
    int bywhat = Util.getIntValue(request.getParameter("bywhat"));
	try {
		JSONArray dataList = new JSONArray();
		ResourceComInfo resourceComInfo = new ResourceComInfo();
		DepartmentComInfo departmentComInfo = new DepartmentComInfo();
		Calendar calendar = Calendar.getInstance();
		int year;
		int month;
		int day;
		if (!currentdate.equals("")) {
			year = Util.getIntValue(currentdate.substring(0, 4));
			month = Util.getIntValue(currentdate.substring(5, 7)) - 1;
			day = Util.getIntValue(currentdate.substring(8, 10));
			calendar.set(year, month, day);
		}

		year = calendar.get(1);
		month = calendar.get(2) + 1;
		day = calendar.get(5);
		if (bywhat == 2) {
			currentdate = Util.add0(year, 4) + "-" + Util.add0(month, 2);
		} else {
			currentdate = Util.add0(year, 4) + "-" + Util.add0(month, 2) + "-" + Util.add0(day, 2);
		}
		MeetingRoomReport roomReport = new MeetingRoomReport();
		String sqlwhere = "where 1=1 and  (meeting.meetingstatus=2 or meeting.meetingstatus=1) ";
		sqlwhere = sqlwhere + roomReport.getDateCSql(currentdate, bywhat);
		baseBean.writeLog(">>>>>getMeetingInfo>>>>sqlwhere:" + sqlwhere);
		rs.executeQuery("select name,contacter,concat(begindate,' ',begintime) begindatatime,concat(enddate,' ',endtime) enddatatime,address from meeting\n" + sqlwhere);
		while (rs.next()){
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("name", Util.null2String(rs.getString("name")));
			String contacter = Util.null2String(rs.getString("contacter"));
			String contactername =resourceComInfo.getLastname(contacter);
			String departmentID =resourceComInfo.getDepartmentID(contacter);
			jsonObject.put("contacter", contactername);
			jsonObject.put("contacterdept", departmentComInfo.getDepartmentName(departmentID));
			jsonObject.put("begindatatime", Util.null2String(rs.getString("begindatatime")));
			jsonObject.put("enddatatime", Util.null2String(rs.getString("enddatatime")));
			jsonObject.put("address", Util.null2String(rs.getString("address")));
			dataList.add(jsonObject);
		}
		jsonData.put("datas", dataList);
	}catch (Exception e){
		e.printStackTrace();
	}
    out.print(jsonData.toJSONString());
%>
